package org.reliablesource.prism.gef.editor;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.ConnectionCreationToolEntry;
import org.eclipse.gef.palette.MarqueeToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.PanningSelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;
import org.reliablesource.prism.gef.editor.model.StickyNoteAdapter;
import org.reliablesource.prism.gef.editor.model.Wire;



/**
 * Utility class that can create a GEF Palette.
 * @author Dennis Park
 */
final class PrismScreenEditorPaletteFactory {
	
	
	/**
	 * Creates the PaletteRoot and adds all palette elements.
	 * Use this factory method to create a new palette for your graphical editor.
	 * @return a new PaletteRoot
	 */
	static PaletteRoot createPalette() {
		PaletteRoot palette = new PaletteRoot();
		palette.add(createTools(palette));
		palette.add(createaddOnsDrawer());
		
		return palette;
	}
	
	/** Create the "Tools" */
	private static PaletteContainer createTools(PaletteRoot palette) {
		PaletteGroup toolGroup = new PaletteGroup("Tools");
		
		// Add a selection tool to the group
		ToolEntry tool = new PanningSelectionToolEntry();
		toolGroup.add(tool);
		palette.setDefaultEntry(tool);
//		
		// Add a marquee tool to the group
		toolGroup.add(new MarqueeToolEntry());
//		
		// Add a (unnamed) separator to the group
		toolGroup.add(new PaletteSeparator());

				
		// Add Change ScreenAdapter image tool 
//		tool = new ToolEntry(
//				"Load Picture",
//				"Load Background picture",
//				PrismEditorPlugin.getImageDescriptor("icons/rectangle16.gif"),
//				PrismEditorPlugin.getImageDescriptor("icons/rectangle24.gif"),
//				LoadBackgroundImageTool.class){};
//		toolGroup.add(tool);
		
		// Add (solid-line) connection tool 
		tool = new ConnectionCreationToolEntry(
				"Redefine path",
				"Define an exact animation path",
				new CreationFactory() {
					public Object getNewObject() { return null; }
					// see ShapeEditPart#createEditPolicies() 
					// this is abused to transmit the desired line style 
					public Object getObjectType() { return Wire.SOLID_CONNECTION; }
				},
				PrismEditorPlugin.getImageDescriptor("icons/newConnection.gif"), 
				PrismEditorPlugin.getImageDescriptor("icons/newConnection.gif"));
				toolGroup.add(tool);
						
//		tool = new ToolEntry(
//				"Text Popup",
//				"Insert a Annotative Text Popup Box to this screen",
//				PrismEditorPlugin.getImageDescriptor("icons/rectangle16.gif"),
//				PrismEditorPlugin.getImageDescriptor("icons/rectangle24.gif"),
//				AnnotationTool.class){};
//		toolGroup.add(tool);
		
						
		return toolGroup;
	}
	
	private static PaletteContainer createaddOnsDrawer() {
		PaletteDrawer componentsDrawer = new PaletteDrawer("Prism Add Ons");
		CombinedTemplateCreationEntry component;
		
		component = new CombinedTemplateCreationEntry(
				"Text Box", 
				"Add a Text Box to the Screen", 
				StickyNoteAdapter.class,
				new SimpleFactory(StickyNoteAdapter.class), 
				PrismEditorPlugin.getImageDescriptor("icons/rectangle16.gif"), 
				PrismEditorPlugin.getImageDescriptor("icons/rectangle24.gif"));
		componentsDrawer.add(component);	
		
//		component = new CombinedTemplateCreationEntry(
//				"Add Path Location", 
//				"Improve pointer's animated path by specifying extra path locations", 
//				PointerLocation.class,
//				new SimpleFactory(PointerLocation.class), 
//				SharedImages.DESC_SELECTION_TOOL_16,SharedImages.DESC_SELECTION_TOOL_24); 
//		componentsDrawer.add(component);
		
		return componentsDrawer;
	}
	
}